Skip to content

Conversation

@timfish
Copy link
Member

@timfish timfish commented Jul 2, 2025

This PR adds support for transforming code with sourcemaps which means the original code positions in the sourcemaps get updated when we inject code.

I also updated the wasm JavaScript tests to use vitest with proper snapshots rather than our manual cobbled together solution.

The JavaScript transform interface now looks like this:

export interface TransformOutput {
    /**
     * The transformed JavaScript code
     */
    code: string;
    /**
     * The sourcemap for the transformation (if generated)
     */
    map: string | undefined;
}

export type ModuleType = "esm" | "cjs" | "unknown";

export class Transformer {
  private constructor();
  free(): void;
  /**
   * Transform the given JavaScript code with optional sourcemap support.
   * # Errors
   * Returns an error if the transformation fails to find injection points.
   */
  transform(code: string, module_type: ModuleType, sourcemap?: string | null): TransformOutput;
}

@timfish timfish marked this pull request as ready for review July 2, 2025 15:15
@jsumners-nr
Copy link
Contributor

Sorry, I really can't review this. I don't have any experience with source maps, TypeScript, nor Rust. Truly, a trifecta of everything I avoid.

@timfish
Copy link
Member Author

timfish commented Jul 27, 2025

I've added an extra test that builds some typescript code, transforms both javascript and sourcemap and then use the source-map library to confirm the original location lookups work.

@timfish timfish requested review from AbhiPrasad and bizob2828 and removed request for AbhiPrasad and bizob2828 July 27, 2025 21:35
@timfish timfish merged commit 288764e into apm-js-collab:main Jul 28, 2025
1 check passed
@timfish timfish deleted the feat/sourcemap-support branch July 28, 2025 14:07
@bizob2828 bizob2828 mentioned this pull request Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants